package com.wisdytech.linkdcs.tool.action;

import com.github.pagehelper.PageInfo;
import com.wisdytech.common.bean.Filter;
import com.wisdytech.common.bean.StandardResult;
import com.wisdytech.common.bean.StandardTableResult;
import com.wisdytech.common.handler.ResourceMatchingService;
import com.wisdytech.common.utils.BaseUtil;
import com.wisdytech.linkdcs.system.model.SysUser;
import com.wisdytech.linkdcs.tool.model.TtEqTool;
import com.wisdytech.linkdcs.tool.service.IToolCheckRecordService;
import com.wisdytech.linkdcs.tool.service.ITtEqToolService;
import com.wisdytech.linkdcs.tool.vo.ToolCheckVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhanghailin
 * @since 2018-06-11
 */
@Controller
@RequestMapping("/tool/check")
public class ToolCheckAction {

    @Resource
    private ITtEqToolService ttEqToolService;

    @Resource
    private IToolCheckRecordService toolCheckRecordService;
    @Autowired
    @Qualifier("resourceMatchingService")
    private ResourceMatchingService resourceMatchingService;
    /**
     *
     * <p>Description: 工装检验</p>
     * @param model model
     * @return String
     */
    @RequestMapping("/index")
    public String toolCheckIndex(Model model, HttpServletRequest httpRequest){
        this.resourceMatchingService.getResourceName(httpRequest,model);
        return "tool/toolCheck";
    }

    @RequestMapping(value = "/getToolCheckList/get.mvc")
    @ResponseBody
    public StandardTableResult<TtEqTool> getToolCheckList(String toolCode, String toolName, String toolModel, String toolType, String opCode, String nextCheckDateStart, String nextCheckDateEnd, Filter filter) {
        PageInfo<TtEqTool> page = ttEqToolService.getToolCheckList(toolCode,toolName,toolModel,toolType,opCode,nextCheckDateStart,nextCheckDateEnd,filter);
        return new StandardTableResult<>(page.getTotal(),page.getList());
    }

    @RequestMapping(value = "/getToolCheckInfo/get.mvc")
    @ResponseBody
    public StandardResult getToolCheckInfo(String toolCode) {
        ToolCheckVO vo = ttEqToolService.getToolCheckInfo(toolCode);
        return StandardResult.getSuccessResult(vo);
    }

    @RequestMapping(value = "/toolCheck/save.mvc")
    @ResponseBody
    public StandardResult toolMaintain(@RequestBody ToolCheckVO vo) {
        SysUser operator = BaseUtil.getCurrentUser();
        this.toolCheckRecordService.toolCheck(vo,operator);
        return StandardResult.getSuccessResult();
    }
}
